//
//  JYRoot.m
//  s.
//
//  Created by fanshijian on 2022/8/29.
//  Copyright © 2022 J. All rights reserved.
//

#import "JYRoot.h"
#import "CALayer+ZHExtension.h"


@implementation JYRoot

#pragma mark - 逻辑跳转



#pragma mark - Bottom Alert View
+ (JYPopContainerView *)popBottomView:(UIView *)view
                          toSuperView:(UIView *)superView
                            animation:(BOOL)animation
                                maker:(void(^)(MASConstraintMaker *make))makerBlock
                                block:(JYPopVoidBlock)block {
    JYPopContainerView *popView = [[JYPopContainerView alloc] initWithSuperView:superView withView:view];
    if (animation) {
        popView.dismissAnimationBlock = ^(JYPopVoidBlock  _Nonnull handelBlock) {
            [view.layer transitionWithType:@"reveal" subtype:@"fromBottom" duration:0.15 function:kCAMediaTimingFunctionEaseOut];
            view.hidden = YES;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                if (handelBlock) {
                    handelBlock();
                }
            });
        };
    }
    popView.backViewColor = S_HexColor(@"#000000");
    popView.backViewAlpha = 0.3;
    popView.isTapBack = YES;
    [popView showBlock:block];

    if (makerBlock) {
        [view mas_makeConstraints:makerBlock];
    }

    if (animation) {
        [view.layer transitionWithType:@"moveIn" subtype:@"fromTop" duration:0.15 function:kCAMediaTimingFunctionEaseOut];
    }
    return popView;
}

+ (JYPopContainerView *)popBottomView:(UIView *)view
                               animation:(BOOL)animation
                                   maker:(void(^)(MASConstraintMaker *make))makerBlock
                                   block:(JYPopVoidBlock)block {
    UIView *window = [UIApplication sharedApplication].keyWindow;
    return [self popBottomView:view toSuperView:window animation:animation maker:makerBlock block:block];
}


@end
